package com.laihui.activity;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.laihui.MyApplication;
import com.laihui.base.BaseActivity;
import com.laihui.entity.RealBean;
import com.laihui.view.TopBar;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * 系统设置
 */
public class SafeCenterActivity extends BaseActivity {
    @BindView(R.id.topbar)//topbar
            TopBar topbar;

    @BindView(R.id.ll_change_login_password)//修改登录密码
            LinearLayout llChangeLoginPassword;
    @BindView(R.id.ll_change_deal_password)//修改交易密码
            LinearLayout llChangeDealPassword;
    @BindView(R.id.tv_realname)//客户须知
            TextView tv_realname;
    @BindView(R.id.tv_phone)//客户须知
            TextView tv_phone;
    @BindView(R.id.btn_exit)//客户须知
            Button btn_exit;



    private Activity mActivity;
    private MyApplication application;

    @Override
    public void init() {
        mActivity = SafeCenterActivity.this;
        application = (MyApplication) getApplication();
        topbar.setTitle("安全中心");
        topbar.setOnTopbarClickListener(new TopBar.topbarClickListener() {
            @Override
            public void leftClick() {
                finish();
            }
            @Override
            public void rightClick() {
            }
        });
        tv_phone.setText(application.username.substring(0,3)+"****"+application.username.substring(7,11));
        realName();
      //  bankcard();
    }



    private void realName(){
        Map<String,String> map = new HashMap<>();
        map.put("member_id",application.userId);
        application.apiService.toReal(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<RealBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(RealBean realBean) {

                        if (realBean.item!=null){
                            tv_realname.setText("已认证");
                        }
                         else{
                            tv_realname.setText("未认证");
                        }
                    }
                });
    }


    /**
     * 联系我们
     */
    private void contactUrl() {

    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_setting_new;
    }

    @Override
    public Activity bindActivity() {
        return this;
    }


    @OnClick({R.id.btn_exit,R.id.ll_change_login_password, R.id.ll_change_deal_password,R.id.tv_realname})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_change_login_password://修改登录密码
                startActivity(new Intent(mActivity, ChangeLoginPasswordActivity.class));
                break;
            case R.id.ll_change_deal_password://修改交易密码
                startActivity(new Intent(mActivity, ChangeDealPasswordActivity.class));
                break;
            case R.id.btn_exit:
                application.clearLoginParams();
                Intent intent = new Intent("android.action.user.exit");
                sendBroadcast(intent);
                startActivity(new Intent(mActivity, LoginActivity.class));
                finish();
                break;
            case R.id.tv_realname:
                startActivity(new Intent(mActivity, RealnameActivity.class));
                break;
        }
    }




}
